<?php
require_once('lib/db_connection.php');

$company_id = $_SESSION['company_id'];
$temp_job_id = $_SESSION['temp_job_id'];
$uname = $_SESSION['username'];
//$rou = $_GET['rou'];
$loc = $_GET['loc'];
//$job = $_GET['job'];
$shr = $_GET['shr'];
$smi = $_GET['smi'];
$lod = $_GET['lod'];
$cli = $_GET['cli'];
$type = $_GET['type'];

if($type=='edit')
{
 $sthr = $_GET['sthr'];
 $stmi = $_GET['stmi'];
 $thr = $_GET['thr'];
 $hrs = $_GET['hrs'];
 $aod = $_GET['aod'];
 $mil = $_GET['mil'];
 $lid = $_GET['lid'];
 $jid = $_GET['jid'];
}

$loc_err = $loc==''?1:0;
$cli_err = $cli==''?1:0;

if($loc_err==1 || $cli_err==1)
{
 echo "new Array(\"$loc_err\",\"$cli_err\");";
}
else
{
 if($type=='add')
 {
 mysql_query("INSERT rou_job_loc_tbl
       (company_id,
       temp_job_id,
       location,
       start_hrs,
       start_min,
       last_odometer,
       client,
       edit_who)
       VALUES
       ('".$company_id."',
       '".$temp_job_id."',
       '".$loc."',
       '".$shr."',
       '".$smi."',
       '".$lod."',
       '".$cli."',
       '".$uname."')
       ") or die("error ".mysql_error());
 }
 if($type=='edit')
 {
  $query_up_loc = "UPDATE rou_job_loc_tbl
       SET
       company_id='".$company_id."',
       location='".$loc."',
       start_hrs='".$shr."',
       start_min='".$smi."',
       stop_hrs='".$sthr."',
       stop_min='".$stmi."',
       total_hrs='".$thr."',
       hrs='".$hrs."',
       last_odometer='".$lod."',
       arrival_odometer='".$aod."',
       miles='".$mil."',
       client = '".$cli."',
       edit_who='".$_SESSION['username']."'
       WHERE loc_id='".$lid."'";
	   
  mysql_query($query_up_loc) or die("UPDATE LOC ".mysql_error());
 }
 //SUCCESS	   
 if($type=='add')
 echo "new Array(\"2\",\"2\",\"add\");";
 if($type=='edit')
 echo "new Array(\"2\",\"2\",\"edit\");";
}
?>